package com.fenghongzhang.day019;

import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.provider.MediaStore;

import java.util.ArrayList;
import java.util.List;

public class MusicUtil {


    public static final int ORDER = 0;
    public static final int RANDOM = 1;
    public static final int SINGEL = 2;

    //数据,让listview来用
    public static List<Song> getMusic(Context context){
        List<Song> list = new ArrayList<>();

        ContentResolver contentResolver = context.getContentResolver();

        Cursor query = contentResolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, null);
        if(query != null){

            while (query.moveToNext()){
                String title = query.getString(query.getColumnIndex(MediaStore.Audio.Media.TITLE));
                String artist = query.getString(query.getColumnIndex(MediaStore.Audio.Media.ARTIST));
                String duration = query.getString(query.getColumnIndex(MediaStore.Audio.Media.DURATION));
                String data = query.getString(query.getColumnIndex(MediaStore.Audio.Media.DATA));
                String size = query.getString(query.getColumnIndex(MediaStore.Audio.Media.SIZE));

                //过滤段玲生
                if (Integer.parseInt(duration) > 1000 * 60){
                    Song song = new Song(title, artist, duration, data, size, null);
                    list.add(song);
                }

            }
            query.close();
        }


        return list;
    }
}
